#include <rtdevice.h>
#include <rtthread.h>
#include <board.h>

extern void cdc_acm_init(uint8_t busid, uintptr_t reg_base);
extern void cdc_acm_data_send_with_dtr_test(uint8_t busid);
extern void msc_ram_init(uint8_t busid, uintptr_t reg_base);
extern void cdc_acm_msc_init(uint8_t busid, uintptr_t reg_base);
extern void cdc_acm_data_send_with_dtr_test(uint8_t busid);
extern void hid_mouse_init(uint8_t busid, uintptr_t reg_base);
extern void hid_mouse_test(uint8_t busid);
extern void hid_keyboard_init(uint8_t busid, uintptr_t reg_base);
extern void hid_keyboard_test(uint8_t busid);
extern void cdc_acm_hid_msc_descriptor_init(uint8_t busid, uintptr_t reg_base);
extern void msc_norflash_init(uint8_t busid, uintptr_t reg_base);
extern void msc_sdcard_init(uint8_t busid, uintptr_t reg_base);
extern void msc_blkdev_init(uint8_t busid, uintptr_t reg_base);

static void cdc_test_thread_entry(void *parameter)
{
    // cdc_acm_init(0, USB_OTG_HS_PERIPH_BASE);

    // while (1) {
    //     rt_thread_mdelay(500);
    //     cdc_acm_data_send_with_dtr_test(0);
    // }

    // msc_ram_init(0, USB_OTG_HS_PERIPH_BASE);

    // while (1) {
    //     rt_thread_mdelay(500);
    // }

    // cdc_acm_msc_init(0, USB_OTG_HS_PERIPH_BASE);

    // while (1) {
    //     rt_thread_mdelay(500);
    //     cdc_acm_data_send_with_dtr_test(0);
    // }

    // hid_mouse_init(0, USB_OTG_HS_PERIPH_BASE);

    // while (1) {
    //     rt_thread_mdelay(500);
    //     hid_mouse_test(0);
    // }

    // hid_keyboard_init(0, USB_OTG_HS_PERIPH_BASE);

    // while (1) {
    //     rt_thread_mdelay(500);
    //     hid_keyboard_test(0);
    // }

    // cdc_acm_hid_msc_descriptor_init(0, USB_OTG_HS_PERIPH_BASE);

    // while (1) {
    //     rt_thread_mdelay(500);
    //     cdc_acm_data_send_with_dtr_test(0);
    //     hid_mouse_test(0);
    // }

    rt_thread_mdelay(500); /*加一点延时, 很好*/
    msc_blkdev_init(0, USB_OTG_HS_PERIPH_BASE);

    while (1) {
        rt_thread_mdelay(500);
    }    

}

static int test_cdc(void)
{
    rt_thread_t tid;
    
    tid = rt_thread_create("cdc_test", 
                         cdc_test_thread_entry, 
                         RT_NULL,
                         4096,
                         20,
                         10);
    if (tid != RT_NULL) {
        rt_thread_startup(tid);
    }
    
    return RT_EOK;
}

INIT_APP_EXPORT(test_cdc);